#include<cstdio>//uncle-lu
#include<algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

int n;
int line[30];
int map[30][30];
int F[30], Nx[30];

int DFS(int x)
{
	if(F[x])return F[x];

	for (int i = x+1; i <= n; i++) 
		if(map[x][i] && F[x] < DFS(i))
		{
			Nx[x] = i;
			F[x] = DFS(i);
		}

	F[x] += line[x];

	return F[x];
}

int main()
{
	read(n);
	for (int i = 1; i <= n; i++) 
		read(line[i]);
	for (int i = 1; i < n; i++) 
		for (int j = i+1; j <= n; j++) 
			read(map[i][j]);

	int ans = 0, sit = 0;
	for (int i = 1; i <= n; i++) 
	{
		if(ans < DFS(i))
		{
			sit = i;
			ans = DFS(i);
		}
	}

	for (int i =  sit; i; i = Nx[i]) 
		printf("%d ", i);
	printf("\n%d", ans);
	return 0;
}
